//
//  OCTabBarController.m
//  OCWeiBo
//
//  Created by mac on 16/3/18.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "OCTabBarController.h"
#import "OCHomeViewController.h"
#import "OCTabBar.h"

@interface OCTabBarController ()<OCTabBarDelegate>

@end

@implementation OCTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    OCTabBar *tabBar = [[OCTabBar alloc]init];
    
    //设置代理
    tabBar.delegate = self;
    
    [self setValue:tabBar forKey:@"tabBar"];
    
    //原因为只读属性，但是要调用，只能用KVC赋值
//    self.tabBar = tabBar;
    

    OCHomeViewController *HomeVC = [OCHomeViewController new];
    [self addChildViewController:HomeVC imageName:@"tabbar_home" title:@"首页"];
    
    
    UITableViewController *MessageVC = [UITableViewController new];
    [self addChildViewController:MessageVC imageName:@"tabbar_message_center" title:@"消息"];
    
    
    UITableViewController *DiscoverVC = [UITableViewController new];
    [self addChildViewController:DiscoverVC imageName:@"tabbar_discover" title:@"发现"];
    
     
    UITableViewController *profileVC = [UITableViewController new];
    [self addChildViewController:profileVC imageName:@"tabbar_profile" title:@"我"];
     
}

-(void)addChildViewController:(UIViewController *)childCtrl imageName:(NSString *)name title:(NSString *)title{

    //设置标题
    childCtrl.tabBarItem.title = title;
    
    childCtrl.navigationItem.title = title;
  
    //指定一下属性
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    //指定选中状态下文字的颜色
    [childCtrl.tabBarItem setTitleTextAttributes:dic forState:UIControlStateSelected];
    
    
    //设置图片，并去掉绿镜的模式
    childCtrl.tabBarItem.image = [[UIImage imageNamed:name]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    childCtrl.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",name]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UINavigationController * nav = [[UINavigationController alloc]init];
    
    [self addChildViewController:[nav initWithRootViewController:childCtrl]];
    
    
}

//实现代理的方法
-(void)tabBar:(OCTabBar *)tabBar didSelectedPlusButtonClick:(UIButton *)button{
    
    NSLog(@"加号按钮点击了");
    
}


@end
